package drg_group.wuxi_2022.MDC;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import drg_group.wuxi_2022.Base;
import drg_group.wuxi_2022.MedicalRecord;
import drg_group.wuxi_2022.ADRG.*;

public class MDCS{
    public static String group(MedicalRecord record){
        String[] mdc_zd={"A49.814","B77.800x004","A52.801","A21.300x002","T82.700x001","A49.002","A30.200x001","A41.806","B76.900x003","A50.500x001","A31.100","A41.503","A66.200","B34.200","A49.800x019","B52.000","B65.101","A51.100x001","B39.500","A75.300x001","A18.100x021+N37.8*","B66.800x002","B01.801","A41.200","A42.805","A74.900","B69.800x003","T82.700x004","B03.x00x003","B66.800x004","A95.100","A48.100x003","T82.701","B85.100","B37.700x001","B48.200","A40.903+N16.0*","A41.506","B36.801","B74.400x003","B27.001","B83.800x008","A31.002","A31.800x001","A02.000x010","B71.800","B83.201","B67.907","A97.900","A18.206","B87.800x001","A18.208","A24.300","A53.000x002","A92.400","B83.800x006","B69.800x004","B88.800x001","A69.900","B65.300","A21.700","A41.502","B25.800x001","B83.900","A02.002","A19.100","A63.800","A31.802","B88.900x001","B36.800","B69.804","A99.x00","A40.000","B38.900","A02.000x009","A50.500","A30.400","A42.803","A32.900","B08.200x002","T85.712","A24.102","A77.300","B74.400x002","A75.000x004","A49.800x023","A49.800x015","A01.400","R50.900x002","A53.900","T82.700x008","B99.x00x001","B67.901","T81.404","T81.402","A01.200","B34.300","A41.400x001","B88.300","B88.000x003","B67.906","B69.805","B08.801","B88.200x001","A42.800x002","B47.000","B74.000x001","A56.200","B74.400","B83.100","A38.x00x013","A18.100x025+N29.1*","A06.000x001","A30.900x004","A54.100x002","A42.200","A42.700","B67.700x001","B48.000","B41.700","B66.100","A40.800","R50.802","B05.900x005","B38.700","B83.400","A02.100x002","A18.801+E35.8*","B46.500","B57.200x001","A93.200","A25.000x001","B34.900","B83.800x009","A20.100","A54.900","A32.700","B40.800","A24.002","B52.900x001","A95.900","A69.800","A18.200x010","B75.x00","A31.800x005","B57.300","A60.001","B03.x00x004","B52.000x002+N08.0*","A50.000","B67.302+E35.0*","B42.100","A54.900x002","A20.801","B60.000","A92.300x004","P37.300","A25.900","A77.000","A01.000x012","B71.100","A27.900x002","A41.900x004","R50.801","B87.100","A01.000x007","A69.200","B00.204","A63.000","A54.500","A56.301","A01.000x018","B45.800x002","T81.400x001","A30.900","B42.800","T82.700x005","A30.300x001","B65.000x001","T81.405","A49.100x006","A79.801","A31.000x001","A02.001","A49.301","A77.000x001","A27.000","B85.000","T86.807","A38.x00x010","A67.200","B44.900x001","A31.000x004","B02.800x001","A06.000","B44.800x003","B50.900x001","A92.000","A67.000","A02.000x005","A41.900","A96.800","R50.901","B83.800x003","A79.900","A93.000","A02.003","B00.700","B48.402","A30.100x003","B55.000x001","B57.100","B37.800x088","B34.400","A49.817","B55.000","B77.800x002","A52.300","B74.900x003","A18.207","B74.800x001","B81.100","T85.711","A21.100","A92.200","B89.x00","B49.x00x021","B74.100x001","B26.800x008+N08.0*","A26.900","A49.800x003","A66.800","A30.500x001","B49.x00x013","B67.600x002","A01.000x017","A93.100","A48.100x001","B03.x00x002","A44.900","A18.813+D77*","B88.900x002","A51.300x004","B74.000x003","A18.107+N29.1*","T85.701","T88.000","B66.101","B67.902","B05.400","B34.300x002","B57.500","A31.800x004","B01.800x002+N08.0*","A92.300","A49.815","A63.003","A68.900","B65.800x002","B81.400","B05.900x001","A21.800","A21.700x002","B66.900","B66.901","A49.806","A20.700","A48.400","B05.801","B27.900x001","T85.700x104","A43.801","A50.400","B54.x00x008","A58.x00","B08.400x003","B65.200x001","B53.100","B69.803","B87.300","A23.900x001","A52.100","B83.200x003","B02.900x003","T79.300x001","A77.200","B90.102+N29.1*","A59.001+N37.0*","A57.x00x002","B05.800x010","B55.000x003","B18.904+N08.0*","A22.700","B00.902","B68.000","A36.900x002","A42.804","B46.900x002","A52.200","B41.900","A43.900","B37.808","A31.900x001","B65.800x001","B05.800x008","T85.703","A41.804","B05.900x002","A42.100","B78.902+N08.0*","B18.205+N08.0*","A48.800x002","B34.000","B66.400","T82.700x002","B80.x00","A18.108+N33.0*","A77.800","A18.106+N29.1*","A30.100x001","A42.000","A66.300","A79.800x002","A97.100","B71.900","A38.x00x011","B41.800x001","A49.001","A49.100x005","A51.302","B45.900","A77.300x001","T81.400x006","B47.900","B83.000x001","A18.101","B39.400x001","B67.400x001","B43.100","B74.400x001","B00.001","A06.200","B83.800x007","A19.200","A56.001","A97.200","B66.200","A30.000x001","A75.100","B48.400","A49.902","B76.100","B27.000","O98.600x001","A44.800","A06.002","B08.000x001","T85.710","B81.000","A67.100","A57.x00x003","B65.100x001","B74.900x005","B44.801","A98.500x001+N08.0*","A49.801","A01.003","A98.200","A01.000x020","A31.000","B06.900x001","B47.100","A01.000x019","A79.000","B67.600x003","A92.300x002","A30.500","A43.802","A49.808","A06.300x001","B74.100x003","A44.000","A02.000","A26.700","B83.800x005","J10.800x002","A23.000","B37.802","B88.000x002","A36.804+N16.0*","B68.100","B48.300","A56.000x003","B27.800","A40.900","A23.900x004","B55.900","A20.000x001","A18.104+N29.1*","A48.000","B49.x11","A41.904+N16.0*","A66.600","B54.x00x004","B74.900","B88.900x003","B81.800x001","A49.201","A56.400","A56.302","B76.901","A49.803","B65.900x007","A26.700x001","A54.809","B50.801","A68.100","B85.400","T85.702","B00.202","A18.100x022+N37.8*","B51.800","A23.300","A23.900x003","A66.000","A31.102","A31.800x002","A49.100x004","R50.900","B34.800x002","A54.900x001","A92.300x001","A19.900","B48.401","A56.300x001","A48.100","A92.900","B37.801","T85.700x809","B43.900","A38.x00","A65.x00","A51.000x002","A23.900x006","A55.x00","T81.400x004","A06.200x001","B42.100x003","B00.900x005","B33.800","A38.x00x012","A27.900x004","A41.800x002","A44.100","A20.101","A64.x00","B48.000x001","B66.300x001","A98.000","A23.000x001","T85.700x808","A02.100","B88.800x004","A22.200","A49.901","A51.300x003","A41.801","A41.807","A06.800x001","B08.100","A27.800","B68.900x002","A28.200","T82.700x009","A43.800x001","T85.708","B74.200x001","A92.300x003","A49.004","A48.801","B42.900","A32.701","A19.901","B56.100x001","A96.200","B66.800x007","A40.100","T81.401","A31.101","A18.103+N29.1*","A49.101","B08.800x004","B34.400x001","B74.901","A78.x00","A20.802","B44.700","B57.200x003","A43.100","A49.813","A51.200","A51.900","B00.701","A31.901","B43.801","B66.902","B66.800x003","B05.802","B01.900x001","B37.401+N37.0*","A18.700+E35.1*","B70.000","A30.200","A30.800","B48.300x001","B66.000x001","A42.900","A96.900","A18.200x006","A94.x01","B46.800x002","B56.000x001","B60.800x001","A01.000x006","A27.900x005","A59.900","B45.700","A50.600","A20.803","B85.300","B69.900x001","A20.900x002","A98.800","A75.900","B08.800x006","B37.700","B67.905","A66.400","A35.x00x001","A52.700x001","A54.001","B88.800x002","B78.700","A32.803","A32.000","A97.000","T85.706","A42.802","A28.801","B34.102","A66.100","A49.811","B99.x01","A06.900","B37.900","B08.000x002","B46.100x001+G99.8*","B81.801","B81.300","A31.001","A52.800","B42.100x002","A02.000x007","A20.800x004","B08.300","A41.000","A92.100","A31.800x003","B02.700","B66.500","B67.903","B81.200","T81.400x002","A06.800x002","B69.801","A38.x00x014","A54.602","A59.000","A24.202","A51.304","B37.800x085","A20.800x005","A41.500x083","B76.900","B76.800","A01.000x004","A18.800x001","A18.211","A01.300","A18.700x002+E35.1*","A22.100x003","B34.101","B54.x00x006","A02.901","B65.900x008","B88.100","B78.901","B74.200x002","B83.200x001","B74.000x002","P37.000","A30.900x008","A21.900x001","A49.003","A66.700","A95.000","B66.800x006","A24.100x003","A02.900x002","A23.903+N16.0*","A41.803","A49.812","B44.100x003","A67.900","A30.900x002","A51.301","A98.300","B67.904","A63.001","B81.802","R50.800x002","A96.100","A22.900","B43.800","A02.900x004","T84.701","A40.300","B49.x18","B83.800x004","A54.600x001","A23.800","A75.001","A67.300","A19.902","A77.900","A36.800x005+N33.8*","B34.100","A75.200x001","B02.900x002","B69.800x008","A22.200x001","A98.100","A75.000x003","A77.200x001","R50.803","A23.100x001","B25.900x002","A20.300","B00.901","B33.100","B49.x02+E35.8*","A51.400x010","A42.200x002","B42.100x001","B50.800","B51.000x001+D77*","A51.002","B69.100","A93.802","B76.000","B83.000","T81.406","A96.100x001","B51.000","A06.300","T80.200","A31.800x006","B39.400","A31.100x002","B00.900x007","B48.800x001","B68.900x004","T85.700x103","A41.300","B66.800x005","T98.200x021","R68.801","A75.000x002","B02.900x001","A98.400x001","B79.x00","A01.000x009","B83.300","A27.800x001","A68.000","B04.x00","B55.200x001","A28.900","A49.802","B33.000","A21.000","B39.900","B83.800x001","A50.100","A51.500","A54.002","A26.800x001","A27.900x006","A36.900","A66.900","A77.900x001","A41.100x002","B65.800x003","B66.400x001","B69.800x005","A28.001","A19.200x001","B67.601","A30.400x002","B51.900","A52.100x011","A24.000x002","B33.000x001","A06.001","A54.601","A49.102","A92.500","B52.001+N08.0*","B66.300","B52.800","A01.000x010","A21.800x001","A49.807","A52.900","B34.800x003","A41.500x087","A49.800x020","A93.801","B34.801","B55.100","A98.400","A51.000","A51.001","A21.301","A79.100","A26.000","A18.209","A77.100","A02.800","A30.900x005","A50.900","B46.400","A23.100","B47.100x001","B60.000x001","A31.000x005","A30.300","B48.201","A24.000","B53.800x001","A02.004","A52.101","B77.900","T81.403","A53.000x001","A79.901","T80.200x004","T81.400x005","B74.902","B71.000","A31.800x007","B18.103+N08.0*","A02.900x003","A41.400","B34.800x004","B65.900x006","A70.x00","B55.100x001","B64.x00","A41.802","B01.900x002","A01.000x014","A49.800x014","A56.800","B05.800x009","A20.200","B26.800x004","B67.401","A31.801","T82.700x007","B55.200","B67.600x001","A40.200","A06.100x002","B38.800","B78.000","B39.300","A18.105+N29.1*","A21.300","B48.700","A30.300x002","B00.205","A01.000","A50.401","B74.200x003","A01.000x011","B68.900x003","A02.000x006","A49.103","B33.802","B50.000","B44.802","T82.700x003","A28.000","B66.800x001","A49.900","A28.100","A60.002","A92.001","B07.x00x009","A49.810","A51.400x001","B05.803","B26.805+N08.0*","B83.800x002","B41.800x003","B26.800x010","A48.300","A18.806+E35.0*","A50.200","B46.800x001","B58.801+N16.0*","A51.201","A51.300x002","A54.808","B89.x01","A24.100x002","B49.x00x007","B26.900x001","B37.400x001+N37.0*","A24.400","A18.212","B08.000x004","A31.803","A24.001","A41.501","A41.505","A59.800x001","B26.800x011","B74.100x002","B45.801","B81.800x002","B27.100","B83.000x002","B77.800x005","B40.700","A06.100","B69.802","A23.200","A63.002","A48.800","B01.800x004","B26.804","B87.900","A06.800x003","A24.101","B39.500x001","B56.900x001","B74.300","A30.900x003","A06.700","A01.100","A77.100x001","B77.803","A51.300x005","A19.900x005","A41.101","B66.000","B67.301","A30.400x001","A24.201","B58.900x001","Z03.000","A50.700","A50.400x001","A49.804","A96.000","A48.200","B37.901","A22.000","A51.303","A49.300","P37.100","A01.000x008","B03.x00","T82.700x011","A26.900x002","B34.400x002","B73.x00","A58.x01","B42.700","B08.401","A49.000","T80.201","A60.900","B65.905+N08.0*","B85.200","B08.200","A52.709+N08.0*","A42.801","B33.801","B40.900","T98.200x012","A41.805","A49.200","T82.700x010","B65.001","B70.100","A02.101","A19.900x004","B45.100","B33.300x001","T85.709","A41.504","A18.100x031","A49.805","A20.000","B25.900x001","A25.100x001","B05.901","B76.902","A18.210","B53.000x001","A92.800","B68.901","A52.700x012+N08.0*","B44.800x005"};
        String[] dept_list={};
        if (!(true && Base.contains(mdc_zd,record.zdList[0]))){
            return "";
        }
        
        Base.groupMessages.putMessage(record.Index,"符合MDCS入组条件，匹配规则：主诊断匹配");
        String result;

        result=SB1.group(record);
        if (result.length()>0){
            return result;
        }

        if (false && record.ssList!=null && record.ssList.length>0  && Base.intersect(Base.SS_VALID,record.ssList)){
            Base.groupMessages.putMessage(record.Index,"符合SQY入组条件，存在有效手术操作："+String.join(",",Base.Intersect(record.ssList,Base.SS_VALID)));
            return "SQY";
        }

        result=SR1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SS1.group(record);
        if (result.length()>0){
            return result;
        }

        result=ST1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SU1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SV1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SZ1.group(record);
        if (result.length()>0){
            return result;
        }

        Base.groupMessages.putMessage(record.Index,"不符合MDCS的ADRG入组条件");
        return "";
    }
}

